package cn.tedu.baking.controller;

import cn.tedu.baking.pojo.dto.ContentDTO;
import cn.tedu.baking.pojo.dto.ContentManagementQueryDTO;
import cn.tedu.baking.pojo.vo.*;
import cn.tedu.baking.response.JsonResult;
import cn.tedu.baking.service.IContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/contents")
public class ContentController {
    @Autowired
    IContentService iContentService;
    @PostMapping("add-new")
    public JsonResult addNew(ContentDTO contentDTO){
        iContentService.addNew(contentDTO);
        return JsonResult.ok();
    }
    @GetMapping("management")
    public JsonResult managementList(ContentManagementQueryDTO queryDTO){
        List<ContentManagementVO> list = iContentService.managementList(queryDTO);
        return JsonResult.ok(list);
    }
    @PostMapping("{id}/delete")
    public JsonResult deleteById(@PathVariable Long id){
        iContentService.deleteById(id);
        return JsonResult.ok();
    }
    @GetMapping("{id}/update")
    public JsonResult updateById(@PathVariable Long id){
        ContentUpdateVO vo = iContentService.updateById(id);
        return JsonResult.ok(vo);
    }
    @GetMapping("{type}/{categoryId}/index")
    public JsonResult selectIndex(@PathVariable Integer type,@PathVariable Long categoryId){
        List<ContentIndexVO> contentIndexVOList = iContentService.selectIndex(type,categoryId);
        return JsonResult.ok(contentIndexVOList);
    }
    @GetMapping("{id}/detail")
    public JsonResult selectDetailById(@PathVariable Integer id){
        ContentDetailVO contentDetailVO = iContentService.selectDetailById(id);
        return JsonResult.ok(contentDetailVO);
    }
    @GetMapping("{id}/{userId}/other")
    public JsonResult other(@PathVariable Integer id,@PathVariable Long userId){
        List<ContentSimpleVO> contentSimpleVO = iContentService.selectOther(id,userId);
        return JsonResult.ok(contentSimpleVO);
    }
    @GetMapping("hot/{id}")
    public JsonResult hotList(@PathVariable Integer id){
        List<ContentSimpleVO> contentSimpleVOS = iContentService.selectHotList(id);
        return JsonResult.ok(contentSimpleVOS);
    }
    @GetMapping("{type}/list")
    public JsonResult listByType(@PathVariable Integer type){
        List<ContentIndexVO> contentIndexVOList = iContentService.listByType(type);
        return JsonResult.ok(contentIndexVOList);
    }
    @GetMapping("/search")
    public JsonResult searchByWd(String wd){
        List<ContentIndexVO> list = iContentService.searchByWd(wd);
        return JsonResult.ok(list);
    }
    @GetMapping("admin")
    public JsonResult listForAdmin(){
        List<ContentAdminVO> list = iContentService.listForAdmin();
        return JsonResult.ok(list);
    }
}
